home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / OpenDoc / ProcessMap / CPProcessMap.cpp next >
Text File  |  1995-04-28  |  8KB  |  271 lines

  1. /*
  2.     File:        CPProcessMap.cpp
  3.     Contains:    CPProcessMap OpenDoc part editor class implementation.
  4.                 Built using PartMaker, then modified.
  5.     Written by:    PartMaker
  6.  
  7.     Change History (most recent first):
  8.  
  9.     <3>    4/14/95    JS        Updated for Developer Release 2
  10.     <4>    3/8/95    JS        Updated to b1c13/c14
  11.     <3>    3/8/95    RA        Add tokenized kODPresDefault param to RegisterWindow().
  12.     <2>    2/21/95    RA        Add kODFrameObject param to RegisterWindow().
  13.     <1>    2/2/95    RA        first checked in
  14.     <0>    PartMaker source by E. Soldan, T. Çelik, J. Alfke, R. Adkins, J. Schalk
  15. */
  16.  
  17. #ifndef _PROCESSMAP_
  18. #include "CPProcessMap.h"
  19. #endif
  20.  
  21. //----------------------------------------------------------------------------------------
  22.  
  23. CPProcessMap::CPProcessMap()
  24. {
  25.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_Constructor
  26.     EnteringMethod("\pCPProcessMap::CPProcessMap");
  27.  
  28.     fDirty            = kODFalse;
  29.     fWindowID        = 0;
  30.     fSession          = kODNULL;
  31.     fSelf               = kODNULL;
  32.     fStorageUnit    = kODNULL;
  33.     fMenuBar          = kODNULL;
  34.     fDraftKey         = 0;
  35.  
  36.     // Note that fDisplayFrames is a static field, and therefore
  37.     // its constructor is automatically called before
  38.     // CPProcessMap constructor.
  39. }
  40.  
  41. //----------------------------------------------------------------------------------------
  42.  
  43. CPProcessMap::~CPProcessMap()
  44. {
  45.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_Destructor
  46.     EnteringMethod("\pCPProcessMap::~CPProcessMap");
  47. }
  48.  
  49. //----------------------------------------------------------------------------------------
  50.  
  51. void CPProcessMap::Release(Environment* ev)
  52. {
  53.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_Release
  54.     EnteringMethod("\pCPProcessMap::Release");
  55.  
  56.     if (fSelf->GetRefCount(ev) == 1) {
  57.         // Here is where you would unregister idle time for the part if
  58.         // have registered time.  Note that if you unregister without
  59.         // registering, OpenDoc will crash.  It's not just a simple
  60.         // look-up-and-if-there-remove kind of operation.
  61.  
  62.         // Note that if you unregister idle here, OpenDoc will need to
  63.         // call Release (here) due to it.  This means that when we call
  64.         // to unregister the idle, we are nesting calls to Release.
  65.         // Due to this, I return out of each case, just to make the
  66.         // flow of control of the call(s) to Release more straightforward.
  67.  
  68.         // Note that if you are going to use idle registration, you will
  69.         // need to include "Disptch.h"
  70.  
  71.         fSession->GetDispatcher(ev)->UnregisterIdle(ev,fSelf,NULL);
  72.  
  73.         return;
  74.     }
  75. }
  76.  
  77. //----------------------------------------------------------------------------------------
  78.  
  79. ODID CPProcessMap::Open(Environment* ev, ODFrame* frame)
  80. {
  81.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_Open
  82.     EnteringMethod("\pCPProcessMap::Open");
  83.  
  84.     ODID windowID;
  85.     ODWindow* window = kODNULL;
  86.  
  87.     if (frame) // Doing a View As Window or Open Root
  88.     {
  89.         if (frame->IsRoot(ev))
  90.         {
  91.             windowID = this->PrivOpenSavedWindow(ev, frame);
  92.         }
  93.         else
  94.         {
  95.             //ClockFrame* clockFrame = (ClockFrame*) frame->GetPartInfo(ev);
  96.             //if (clockFrame)
  97.             //    windowID = clockFrame->ViewInWindow(ev);
  98.         }
  99.     }
  100.     else
  101.     {
  102.         windowID = this->PrivOpenInitialWindow(ev);
  103.     }
  104.     return windowID;
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108.  
  109. ODWindow*  CPProcessMap::PrivCreateWindow(Environment *ev,ODFrame* sourceFrame)
  110. {
  111.     // get rectangle
  112.     Rect windRect;
  113.     const ODSShort        kOnePageWidth = 600;
  114.     ::SetRect(&windRect, 4, GetMBarHeight() + 24,
  115.             ODQDGlobals.screenBits.bounds.right - 64,
  116.             ODQDGlobals.screenBits.bounds.bottom - 4);
  117.     if (windRect.right - windRect.left > kOnePageWidth)
  118.         windRect.right = windRect.left + kOnePageWidth;
  119.  
  120.     // get title
  121.     Str255 windowTitleStr;
  122.     ODName*    partName = ODGetPOName(ev, fSelf, kODNULL);
  123.     IntlToPStr(partName, (StringPtr)&windowTitleStr);
  124.     DisposeIText(partName);
  125.  
  126.     ODPlatformWindow platformWindow = ::NewCWindow(kODNULL,
  127.                                                     &windRect,
  128.                                                     windowTitleStr,
  129.                                                     false,
  130.                                                     this->PrivWantResizableWindow() ? zoomDocProc : zoomNoGrow,
  131.                                                     (WindowPtr)-1L,
  132.                                                     true,
  133.                                                     kODNULL);
  134.  
  135.     ODBoolean isRoot = ((sourceFrame == kODNULL) || sourceFrame->IsRoot(ev));
  136.  
  137.     ODWindow* window = fSession->GetWindowState(ev)->RegisterWindow(ev,
  138.                             platformWindow,                                // newWindow
  139.                             isRoot ?                                     // Persistent
  140.                             kODFrameObject:                             // Non-Persistent
  141.                             kODNonPersistentFrameObject,                // frameType
  142.                             isRoot,                                        // isRootWindow
  143.                             this->PrivWantResizableWindow(),                    // isResizable
  144.                             kODFalse,                                    // isFloating
  145.                             kODTrue,                                    // shouldSave
  146.                             fSelf,                                        // rootPart
  147.                             fSession->Tokenize(ev, kODViewAsFrame),        // viewType
  148.                             fSession->Tokenize(ev, kODPresDefault),        // presentation
  149.                             sourceFrame);                                // sourceFrame
  150.     return window;
  151. }
  152.  
  153. //----------------------------------------------------------------------------------------
  154.  
  155. ODID CPProcessMap::PrivOpenInitialWindow(Environment* ev)
  156. {
  157.     ODWindow* window = this->PrivCreateWindow(ev, kODNULL);
  158.     ODID windowID = window->GetID(ev);
  159.     window->Open(ev);
  160.     window->Show(ev);
  161.     window->Select(ev);    
  162.     return windowID;            
  163. }
  164.  
  165. //----------------------------------------------------------------------------------------
  166.  
  167. ODID CPProcessMap::PrivOpenSavedWindow(Environment* ev, ODFrame* frame)
  168. {
  169.     ODWindow* window = kODNULL;
  170.     WindowProperties props;
  171.     
  172.     if (BeginGetWindowProperties(ev, frame, &props))
  173.     {
  174.         ODPlatformWindow platformWindow = NewCWindow(kODNULL, &(props.boundsRect), props.title, 
  175.                     kODFalse, props.procID, (WindowPtr)-1L, props.hasCloseBox, props.refCon);
  176.         
  177.         window = fSession->GetWindowState(ev)->RegisterWindowForFrame(ev, 
  178.                                         platformWindow, 
  179.                                         frame,
  180.                                         props.isRootWindow,    // Keeps draft open
  181.                                         kODTrue,    // Is resizable
  182.                                         kODFalse,    // Is floating
  183.                                         kODTrue,    // shouldSave
  184.                                         props.sourceFrame);
  185.         EndGetWindowProperties(ev, &props); // Release source frame
  186.                 
  187.         window->Open(ev);
  188.         window->Show(ev);
  189.         return window->GetID(ev);
  190.     }
  191.     else 
  192.         return 0;
  193. }
  194.  
  195. //----------------------------------------------------------------------------------------
  196.  
  197. ODBoolean CPProcessMap::PrivWantResizableWindow()
  198. {
  199.     return kODFalse;
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203.  
  204. void CPProcessMap::ReleaseAll(Environment* ev)
  205. {
  206.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_ReleaseAll
  207.     EnteringMethod("\pCPProcessMap::ReleaseAll");
  208.  
  209.     if (fMenuBar != kODNULL)
  210.         fMenuBar->Release(ev);
  211. }
  212.  
  213. //----------------------------------------------------------------------------------------
  214.  
  215. void CPProcessMap::PrivInvalAllDisplayFrames(Environment* ev)
  216. {
  217.     // This is just a CPProcessMap utility method.
  218.  
  219.     for (FrameLink *fl = fDisplayFrames.First(); fl->Frame(); fl = fl->Next())
  220.         fl->Frame()->Invalidate(ev, kODNULL, kODNULL);
  221. }
  222.  
  223. //----------------------------------------------------------------------------------------
  224. // Storage protocol
  225. //----------------------------------------------------------------------------------------
  226.  
  227. void CPProcessMap::IncrementRefCount(Environment* ev)
  228. {
  229.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_IncrementRefCount
  230.     EnteringMethod("\pCPProcessMap::IncrementRefCount");
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234.  
  235. void CPProcessMap::CloneInto(Environment* ev, ODDraftKey key, 
  236.         ODStorageUnit* destinationSU, ODFrame* initiatingFrame)
  237. {
  238.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_CloneInto
  239.     EnteringMethod("\pCPProcessMap::CloneInto");
  240.  
  241.     // We must first verify that we've never written to this storage unit.
  242.     // If we have, we should do nothing, otherwise we need to write out
  243.     // the current state of the part content.
  244.     
  245.     if ( destinationSU->Exists(ev, kODPropContents, kProcessMapKind, 0) == kODFalse )
  246.     {
  247.         // Add the properties we need to successfully externalize
  248.         // ourselves into the destination storage unit.
  249.         this->PrivCheckAndAddProperties(ev, destinationSU);
  250.                 
  251.         // Write out the part's state information.
  252.         this->PrivExternalizeStateInfo(ev, destinationSU, key, initiatingFrame);
  253.             
  254.         // Write out the part's content.
  255.         this->PrivExternalizeContent(ev, destinationSU);
  256.     }
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260.  
  261. ODSize CPProcessMap::Purge(Environment* ev, ODSize size)
  262. {
  263.     // 
  264.     ODUnused(size);
  265.     EnteringMethod("\pCPProcessMap::Purge");
  266.  
  267.     // CPProcessMap doesn't do anything here.
  268.     return 0;
  269. }
  270.  
  271.